package team.seekers.hula.question.answer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.common.entity.VisibilityUpdateDTO;
import team.seekers.hula.question.answer.entity.dto.AnswerQueryDTO;
import team.seekers.hula.question.answer.entity.dto.AnswerUpdateManageDTO;
import team.seekers.hula.question.answer.entity.vo.AnswerManageListVO;
import team.seekers.hula.question.answer.service.AnswerManageService;
import team.seekers.hula.question.answer.service.AnswerService;

import java.util.List;

/**
 * @author Godc
 * @description
 */
@Controller
@ApiResponseBody
@RequestMapping("/manage/answer")
public class AnswerManageController {

    @Autowired
    private AnswerService answerService;

    @Autowired
    private AnswerManageService answerManageService;


    @GetMapping("/delete")
    public void adminDelete(@RequestParam("answerId") String id){
        answerService.adminDelete(id);
    }


    @PostMapping("/pageOrderByTime")
    public PageResult<AnswerManageListVO> pageAdminAnswerCondition(@RequestBody(required = false) AnswerQueryDTO answerQuery){
        return answerService.adminPageOrderByTime(answerQuery.getPageNow(), answerQuery.getPageSize(), answerQuery);
    }

    @GetMapping("/getAllAdminAnswerInfo")
    public List<AnswerManageListVO> getAllAdminAnswerInfo(){
        List<AnswerManageListVO> listAnswerVo =  answerService.getAllAdminAnswerInfo();
        return listAnswerVo;
    }

    @PostMapping("/update/info")
    public void update(@RequestBody AnswerUpdateManageDTO updateVO){
        answerManageService.update(updateVO);
    }

    @PostMapping("/update/visibility")
    public void updateVisibility(@RequestBody VisibilityUpdateDTO updateDTO){
        answerManageService.updateVisibility(updateDTO);
    }

    @GetMapping("/approveExamine")
    public void approveExamine(@RequestParam String id){
        answerManageService.changeApproval(id,1);
    }
    @GetMapping("/failedExamine")
    public void failedExamine(@RequestParam String id){
        answerManageService.changeApproval(id,2);
    }

    @GetMapping("/page")
    public PageResult<AnswerManageListVO> page(AnswerQueryDTO answerQuery){
        return answerManageService.listInManage(answerQuery);
    }

}
